<!DOCTYPE HTML>
<html lang="en"  xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="Bootstrap-ecommerce by Vosidiy">

    <title>修改密码</title>

    <link rel="/shortcut icon" type="image/x-icon" href="/images/favicon.ico">

    <!-- jQuery -->
    <script src="/js/jquery-2.0.0.min.js" type="text/javascript"></script>

    <!-- Bootstrap4 files-->
    <script src="/js/bootstrap.bundle.min.js" type="text/javascript"></script>
    <link href="/css/bootstrap.css" rel="stylesheet" type="text/css"/>

    <!-- Font awesome 5 -->
    <link href="/fonts/fontawesome/css/fontawesome-all.min.css" type="text/css" rel="stylesheet">

    <!-- plugin: fancybox  -->
    <script src="/plugins/fancybox/fancybox.min.js" type="text/javascript"></script>
    <link href="/plugins/fancybox/fancybox.min.css" type="text/css" rel="stylesheet">

    <!-- custom style -->
    <link href="/css/ui.css" rel="stylesheet" type="text/css"/>
    <link href="/css/responsive.css" rel="stylesheet" media="only screen and (max-width: 1200px)" />

    <!-- custom javascript -->
    <script src="/js/script.js" type="text/javascript"></script>

    <script type="text/javascript">
        /// some script

        // jquery ready start
        $(document).ready(function() {
            // jQuery code

        });
        // jquery end
    </script>

</head>
<body>
<header class="section-header">
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <form action="/HTML/userInfo" method="post" name="showUserInfoForm" >
            <a class="navbar-brand" href="javascript:history.go(-1)" name="savesubmit" id="savesubmit"> <img class="logo" src="/images/logo-white.png" th:text="'  '+'修改密码'"></a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar1" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
        </form>

        <div class="collapse navbar-collapse" id="navbar1">
            <ul class="navbar-nav ml-auto">
                <li class="nav-item">
                    <a class="btn ml-2 btn-outline-danger" href="/HTML/relogin">退出登录<span class="sr-only">(current)</span></a>
                </li>
                <li class="new-item">
                    <a class="btn ml-2 btn-outline-success" href="/HTML/home">返回主页</a>
                </li>
                <form action="/HTML/lookOrderList" method="post" name="showUserOrderForm" th:value="${account}">
                    <li class="nav-item">
                        <a class="btn ml-2 btn-outline-primary" href="javascript:showUserOrderForm.submit();">我的订单<span class="sr-only">(current)</span></a>
                    </li>
                </form>
                <li class="nav-item">
                    <a class="btn ml-2 btn-outline-warning" href="javascript:showUserInfoForm.submit();">个人资料</a>
                </li>
            </ul>
        </div>
    </nav>
</header> <!-- section-header.// -->

<div class="card">
    <article class="card-body mx-auto" style="max-width: 400px;">
        <h4 class="card-title mt-3 text-center">修改密码</h4>
        <!--<p class="text-center" th:text="'您的账号为：'+${user.account}"></p>-->
        <p class="divider-text">
            <span>请保证两次输入的密码一致</span>
        </p>
        <form action="/HTML/updatePasswordTo" method="post">
            <div class="form-group input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"> <i class="fa fa-heart"></i>&nbsp;原密码 </span>
                </div>
                <input class="form-control" id="pwd" name="password" onkeydown="ableEdit()" type="password" size="20" placeholder="请输入原密码">
            </div> <!-- form-group// -->
            <div class="form-group input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"> <i class="fa fa-lock"></i>&nbsp;新密码 </span>
                </div>
                <input class="form-control" type="password" placeholder="请输入新密码" name="newPassword" id="pwd1" size="20" onkeydown="ableEdit()">
            </div> <!-- form-group// -->
            <div class="form-group input-group">
                <div class="input-group-prepend">
                    <span class="input-group-text"> <i class="fa fa-lock"></i>&nbsp;确认密码 </span>
                </div>
                <input class="form-control" placeholder="请确认密码" type="password"name="passwordD" id="pwd2" size="20" onkeyup="validate()" onkeydown="ableEdit()">
            </div> <!-- form-group// -->
            <div class="form-group">
                <button  type="reset" class="btn btn-link float-left " onclick="cleantishi()" >重置</button>
                <span id="tishi"></span>
            </div> <!-- form-group// -->
            <div class="form-group">
                <button type="submit" class="btn btn-outline-primary btn-block" id="submit" onclick="isNull()">确认修改</button>
            </div> <!-- form-group// -->
            <input type="hidden" th:value="${flag}">
        </form>
        <form name =form1 method="post" action="/HTML/updatePassword">
            <p class="text-center">点错了？ <a href="javascript:showUserInfoForm.submit();">返回</a> </p>
            <p>【提示】输入原密码后，请创建保密性更高的密码，在确认密码之后点击“确认修改”按钮即可修改密码</p>
        </form>
    </article>
    <br><br><br><br>
</div> <!-- card.// -->

<!-- ========================= FOOTER ========================= -->
<footer class="section-footer bg-dark white">
    <div class="container">
        <section class="footer-bottom row">
            <div class="col-sm-6">
                <p> 四川大学实训项目 <br>  第六组作品</p>
            </div>
            <div class="col-sm-6">
                <p class="text-sm-right">
                    2019 · 7 · 8 <br>
                    中国 · 成都
                    <!--<a href="http://bootstrap-ecommerce.com">Bootstrap-ecommerce UI kit</a>-->
                </p>
            </div>
        </section> <!-- //footer-top -->
    </div><!-- //container -->
</footer>
<script>
    function ableEdit() {
        document.getElementById("submit").disabled = false;
    }
    function validate() {
        var pwd1 = document.getElementById("pwd1").value;
        var pwd2 = document.getElementById("pwd2").value;
        <!-- 对比两次输入的密码 -->
        if(pwd1 == pwd2) {
            document.getElementById("tishi").innerHTML="<font color='green'>两次密码相同</font>";
            document.getElementById("submit").disabled = false;
        }
        else {
            document.getElementById("tishi").innerHTML="<font color='red'>两次密码不相同</font>";
            document.getElementById("submit").disabled = true;
        }
    }

    function isNull() {

        var pwd =document.getElementById("pwd").value;
        var pwd1 =document.getElementById("pwd1").value;
        var pwd2 =document.getElementById("pwd2").value;

        if(pwd==""||pwd==null){
            document.getElementById("submit").disabled = true;
            alert("请先填写原密码");
        }
        else if(pwd1 == "" || pwd1 == null){
            document.getElementById("submit").disabled = true;
            alert("请先填写密码");
        }
        else if(pwd2 == "" || pwd2 == null){
            document.getElementById("submit").disabled = true;
            alert("请填写确认密码项");
        }
        else {
            document.getElementById("submit").disabled = false;
        }
    }
    window.onload=function judge() {
        var flag=[[${flag}]];
        if(flag==1){
            document.getElementById("submit").disabled = true;
            alert("修改密码失败：原密码错误");
            flag=0;
        }
    }
    function cleantishi() {
        document.getElementById("tishi").innerHTML="";
    }
</script>
</body>
